﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.ComponentModel.DataAnnotations;

namespace WangLuo.Pub.Account.Core
{
    public class SysUser : EntityBaseId
    {
        // 无需定义 Id 属性
        // 并自动添加 CreatedTime，UpdatedTime 属性

        /// <summary>
        /// 账号
        /// </summary>
        [Comment("账号")]
        [Required, MaxLength(50)]
        public string Account { get; set; }

        /// <summary>
        /// 密码（默认MD5加密）
        /// </summary>
        [Comment("密码")]
        [Required, MaxLength(64)]
        public string Password { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        [Comment("姓名")]
        [MaxLength(200)]
        public string Name { get; set; }

        /// <summary>
        /// 手机
        /// </summary>
        [Comment("手机")]
        [MaxLength(20)]
        public string Phone { get; set; }

        [Comment("邮箱")]
        [MaxLength(100)]
        public string EMail { get; set; }

        /// <summary>
        /// 头像
        /// </summary>
        [Comment("头像")]
        public string Avatar { get; set; }

        /// <summary>
        /// 性别-男_1、女_2
        /// </summary>
        [Comment("性别-男_1、女_2")]
        public Gender Sex { get; set; }

        /// <summary>
        /// 状态-正常_0、停用_1、删除_2
        /// </summary>
        [Comment("状态-正常_0、停用_1、删除_2")]
        public CommonStatus Status { get; set; } = CommonStatus.ENABLE;

        // 配置数据库实体
        public void Configure(EntityTypeBuilder<SysUser> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder.HasKey(u => u.Id);
            entityBuilder.HasIndex(u => u.Account);
            entityBuilder.HasIndex(u => u.Phone);
        }
    }
}
